package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.BlogDTO;
import com.sky.dto.BlogPageQueryDTO;
import com.sky.entity.Blog;
import com.sky.enumeration.OperationType;
import com.sky.vo.BlogVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface BlogMapper {


    /**
     * 分页查博客
     * @param blogPageQueryDTO
     * @return
     */
    Page<BlogVO> pageQuery(BlogPageQueryDTO blogPageQueryDTO);

    /**
     * 根据id查博客
     * @param blogid
     * @return
     */
    @Select("select *from blog where id =#{blogid}")
    Blog getById(Long blogid);

    /**
     * 新增博客
     * @param blog
     */

    @AutoFill(OperationType.INSERT)
    void insert(Blog blog);

    /**
     * 增加一次浏览量
     * @param id
     */
    @Update("update blog set read_count = read_count + 1 where id=#{id}")
    void addPageView(Long id);

    /**
     * 增加一个评论数
     * @param blogId
     */
    @Update("update blog set comment_count = comment_count + 1 where id=#{id}")
    void addCommentCount(Integer blogId);

    /**
     * 增加点赞
     * @param blogDTO
     */
    @Update("update blog set like_count = like_count + 1 where id=#{id}")
    void addLikeCount(BlogDTO blogDTO);

    /**
     * 取消点赞
     * @param blogDTO
     */
    @Update("update blog set like_count = like_count - 1 where id=#{id}")
    void deleteLike(BlogDTO blogDTO);
}
